<?php

use Illuminate\Database\Seeder;

/**
 * 合同类型
 * 1. 公共配置项带有水电的。
 * 2. 合同为时间标准的合同
 * 3. 出租一个普通的房间
 * 4. 非递增合同
 * 5. 收费周期为1个月
 * 6. 合同时间为 2020-08-03 ~ 2021-01-30
 */
class OwnerSeeder1 extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $imageUrl = "https://zhengxin-pub.cdn.bcebos.com/logopic/7f4ddce77b909531e686938282edc951_fullsize.jpg?x-bce-process=image/resize,m_lfit,w_112";
        // 创建用户
        $user = \App\Models\User::query()->create([
            'name' => '韦汉成',
            'email' => '2049874524@qq.com',
            'mobile' => '13288252461',
            'password' => 'test',
            'gender' => 0,
            'status' => 1,
            'create_admin_id' => 1,
            'update_admin_id' => 1,
            'type' => \App\Models\User::TYPE_DEFAULT
        ]);

        // 获取随机的一个数值
        $randRoom = \App\Models\Room::query()->where('is_rent', false)->inRandomOrder()->first();

        // 一般合同
        $owner = \App\Models\Owner::query()->create([
            'user_id' => $user->id,
            'image' => $imageUrl,
            'cycle' => 1,
            'cycle_unit' => \App\Models\Owner::CYCLE_UNIT_MONTH,
            'cycle_price' => 1999.01,
            'deposit' => 2000.09,
            'description' => 'owner 测试',
            'inc' => 0,
            'contract' => "[\"images\/a03e4e5823ba6cfb6bbc1cc3c79836fe.jpg\"]",
            'create_admin_id' => 1,
            'update_admin_id' => 1,
            'ownerable_id' => $randRoom->id,
            'ownerable_type' => get_class($randRoom),
            'started_at' => \Carbon\Carbon::now(),
            'ended_at' =>  \Carbon\Carbon::now()->addMonths(2),
            'config' => [
                ["house_config_id" => "1", "price" => "1.2"],
                ["house_config_id" => "2", "price" => "4"]
            ],
        ]);

        $room = \App\Models\Room::query()->find($randRoom->id);
        $room->is_rent = true;
        $room->save();

        // 生成基础抄表数据
        \App\Models\Meter::query()->create([
            'value' => 0,
            'house_fee_config_id' => 1,
            'meterable_id' => $randRoom->id,
            'meterable_type' => get_class($randRoom),
            'count' => 0
        ]);

        \App\Models\Meter::query()->create([
            'value' => 0,
            'house_fee_config_id' => 2,
            'meterable_id' => $randRoom->id,
            'meterable_type' => get_class($randRoom),
            'count' => 0
        ]);

        // 添加抄表数据
        (new \App\Services\OwnerService())->handle($owner);
    }
}
